package jdbc.date;

import jdbc.mobel.jdlist;
import jdbc.util.BaseDao;

import java.util.List;
import java.util.Scanner;

public class libraryReturn { //TODO 还书
    public libraryReturn(){
        Scanner dr=new Scanner(System.in);
        String w1="select * from book where id=2301;";
        String w2="select * from book where id=2302;";
        String w3="select * from book where id=2303;";
        String w4="select * from book where id=2304;";
        String w5="select * from book where id=2305;";

        List<jdlist> work1= BaseDao.executeDQL(w1, jdlist.class);
        List<jdlist> work2= BaseDao.executeDQL(w2, jdlist.class);
        List<jdlist> work3= BaseDao.executeDQL(w3, jdlist.class);
        List<jdlist> work4= BaseDao.executeDQL(w4, jdlist.class);
        List<jdlist> work5= BaseDao.executeDQL(w5, jdlist.class);

        System.out.println("--------------------------------------");
        System.out.println("现在有以下图书和剩余数量");
        System.out.println("书名      剩余数量");
        System.out.println("1.水浒传: "+work1.size());
        System.out.println("2.计算机基础: "+work2.size());
        System.out.println("3.数据库原理: "+work3.size());
        System.out.println("4.高等数学: "+work4.size());
        System.out.println("5.离散数学: "+work5.size());
        System.out.println("请输入序号选择您想还的书");
        int a=dr.nextInt();

        switch (a){
            case 1:{
                String j2="insert into book(id,name,math)values (2301,'水浒传',50);";
                BaseDao.executeDML(j2);
                System.out.print("本书剩余数量:  ");
                System.out.println(work1.size()+1);
                break;}

            case 2:{
                String j4="insert into book(id,name,math)values(2302,'计算机基础',31);";
                BaseDao.executeDML(j4);
                System.out.print("本书剩余数量:  ");
                System.out.println(work2.size()+1);
                break;}

            case 3:{
                String j6="insert into book(id,name,math)values(2303,'数据库原理',35);";
                BaseDao.executeDML(j6);
                System.out.print("本书剩余数量:  ");
                System.out.println(work3.size()+1);
                break;}

            case 4:{
                String j8="insert into book(id,name,math)values(2304,'高等数学',42);";
                BaseDao.executeDML(j8);
                System.out.print("本书剩余数量:  ");
                System.out.println(work4.size()+1);
                break;}

            case 5:{
                String j0="insert into book(id,name,math)values(2305,'离散数学',51);";
                BaseDao.executeDML(j0);
                System.out.print("本书剩余数量:  ");
                System.out.println(work5.size()+1);
                break;}
        }
        System.out.println("还书成功,将为您返回登录页面");
        System.out.println("感谢您按时归还,祝您幸福常伴");
        System.out.println("-----------------------------------------");
        libraryDengLu e=new libraryDengLu();
        e.setDeng();
    }
}
